﻿using System;
using System.IO;
namespace rehot
{
    using rehot.plugin;
    public class HotVirtual : IDisposable
    {
        internal RehotAssembly container { get; set; }
        internal byte MODE;
        public Guid Id { get; set; }
        public HotVirtual() {
            this.Id = Guid.NewGuid();
            if (RehotAssembly.Allow)
            {
                this.container = new RehotAssembly("rehot#" + Id);
                MODE = 2;
            }
            else MODE = 0;
        }
        public void LoadDLL(string path)
        {
            path = Path.GetFullPath(path);
            this.container.Load(path);
        }
        public void LoadOneDLL(string path)
        {
            path = Path.GetFullPath(path);
            this.container.Load(File.ReadAllBytes(path));
        }
        public RehotAssemblyContainer GetContainer()
        {
            return this.container.GetContainer();
        }
        public void Dispose()
        {
            if (container != null)
            {
                if (MODE != 0) container.Unload();
                this.container = null;
            }
        }
    }
}
